﻿using LibraryManagement.Custom_Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LibraryManagement.Profile_Management.Setup
{
    public partial class SessionSet : libForm
    {
        private LibManagementEntities context;
        private Session OSession;
        public SessionSet()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            context = new LibManagementEntities();
            context.Sessions.Single(x => x.ActiveSession == true).ActiveSession = false;
            context.SaveChanges();
            context = new LibManagementEntities();
            OSession = context.Sessions.Single(x => x.SessionId == (decimal)cmbSessions.SelectedValue);
            OSession.ActiveSession = true;
            context.SaveChanges();
            context=new LibManagementEntities();
            clsStatics.currentActiveSessionId = context.Sessions.Single(x => x.ActiveSession == true).SessionId;
        }

        private void SessionSet_Load(object sender, EventArgs e)
        {
            context = new LibManagementEntities();
            cmbSessions.SetDataSource(context.Sessions.ToList(), "SessionName", "SessionId");
        }
    }
}
